import React from "react";
import { Link, Routes, Route, Navigate, useNavigate } from "react-router-dom";

const Home = () => {
  const navigate = useNavigate();

  const fn = () => {
    // 相当于push方法
    navigate("/about");

    // 相当于replace方法
    // navigate("/about", { replace: true });

    // 直接加数字相当于go方法
    // navigate(2);
  };

  return (
    <div>
      home页面 - <button onClick={fn}>btn</button>
    </div>
  );
};
const About = () => {
  return <div>about页面</div>;
};

const App = () => {
  return (
    <>
      <h2>router-v6-redirect</h2>
      <ul>
        <li>
          <Link to="/home">home</Link>
        </li>
        <li>
          <Link to="/about">about</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        {/* Navigate */}
        <Route path="/" element={<Navigate to="/home"></Navigate>}></Route>
        <Route path="/home" element={<Home />}></Route>
        <Route path="/about" element={<About />}></Route>
      </Routes>
    </>
  );
};

export default App;
